package com.cat.DataStructure04;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/contest/weekly-contest-478/problems/count-elements-with-at-least-k-greater-values/
 * @create 2025/11/30 10:30
 * @since JDK17
 */

public class Solution25 {
    public int countElements(int[] nums, int k) {
        Arrays.sort(nums);
        int n = nums.length, ans = 0;
        for (int i = 0, j; i < n; ) {
            j = i++;
            while (i < n && nums[i] == nums[i - 1]) {
                i++;
            }
            if (n - i >= k) {
                ans += i - j;
            }
        }
        return ans;
    }
}
